package com.bluesky.service.lesson024.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bluesky.dto.lesson024.UserAddRequest;
import com.bluesky.dto.lesson024.UserModifyRequest;
import com.bluesky.mapper.lesson024.Lesson0024UserMapper;
import com.bluesky.po.lesson024.Lesson024UserPO;
import com.bluesky.service.lesson024.IUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl extends ServiceImpl<Lesson0024UserMapper, Lesson024UserPO> implements IUserService {
 @Override
    @Transactional(rollbackFor = Exception.class)
    public String add(UserAddRequest req) {
        Lesson024UserPO lesson024UserPO = new Lesson024UserPO();
        BeanUtils.copyProperties(req, lesson024UserPO);
        lesson024UserPO.setId(IdUtil.fastSimpleUUID());

        this.save(lesson024UserPO);
        return lesson024UserPO.getId();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean modify(UserModifyRequest req) {
        Lesson024UserPO lesson024UserPO = new Lesson024UserPO();
        BeanUtils.copyProperties(req, lesson024UserPO);

        return this.updateById(lesson024UserPO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(String userId) {
        return this.removeById(userId);
    }
}
